package org.bookie.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.AccessType;

/**
 * Class modelling a category of an {@link Event}.
 * 
 * @author Igor Drobiazko
 */
@Entity
@AccessType("field")
@Table(name="Categories")
public class Category extends CommonEntity {
	private static final long serialVersionUID = 1L;
	/**Name of the category*/
	@Column(nullable = false, unique = true)
	private String name;
	/**List events belonging to this category*/
    @OneToMany(mappedBy="category",fetch=FetchType.LAZY)
	private List<Event> events = new ArrayList<Event>();
	/**Number of currently active events belonging to this category*/
	@Transient private int eventCount;
	/**Number of currently active bets belonging to this category*/
	@Transient private int betCount;
	/**Number of all events belonging to this category*/
	@Transient private int totalEventCount;
	
	/**Constructs an empty instance of Category*/
	protected Category(){super();}
	
	/**
	 * Constructs a new instance of Category
	 * @param name name to set
	 */
	public Category(String name){
		this.name = name;
	}
	
	/**
	 * Get the name of the category
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Set category name
	 * @param name name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Get the {@link Event}s of this category
	 * @return a list of Events
	 */
	public List<Event> getEvents() {
		return events;
	}
	
	/**
	 * Returns the number of currently active events.
	 * Events whose end date is in the past or which have an successful bet are not counted.
	 */
	public int getEventCount() {
		return eventCount;
	}
	
	/**
	 * Set the number of currently active events.
	 * @param eventCount number to set
	 */
	public void setEventCount(int eventCount) {
		this.eventCount = eventCount;
	}
	
	/**
	 * Returns the number of all events. 
	 */
	public int getTotalEventCount() {
		return totalEventCount;
	}
	
	/**
	 * Set the number of all events
	 * @param count number to set
	 */
	public void setTotalEventCount(int count) {
		this.totalEventCount = count;
	}

	public int getBetCount() {
		return betCount;
	}

	public void setBetCount(int betCount) {
		this.betCount = betCount;
	}
}
